//
//  DNSHelper.h
//  hqedu24olapp
//
//  Created by ouyongyong on 16/8/4.
//  Copyright © 2016年 edu24ol. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <YTKRequest.h>
#define kHqEbookHost    (@"hqebook.98809.com")

#define kHqHostList (@[@"uagent.98809.com",@"kjapi.edu24ol.com", @"edu24ol-io.98809.com", @"edu100hqvideo.bs2cdn.100.com", @"mapp.edu24ol.com", @"api.edu24ol.com", @"app-io.98809.com", @"adsdk.io.edu24ol.com", @"fb.98809.com", @"hqo1.bs2dl.yy.com", @"hq.100.com", kHqEbookHost])

@interface DNSHelper : NSObject

+ (DNSHelper *)shareInstance;

/**
 *  记录不可用的HOST
 */
@property (nonatomic, strong) NSSet *badHosts;

//记录被污染的host什么时候恢复正常流程
@property (nonatomic, readonly) NSDictionary *badHostLifeDict;
/** hq_userId */
@property (nonatomic, strong) NSNumber *hq_userId;


//请求初期是否使用IP
- (BOOL)shouldUseIpForRequest:(YTKRequest *)request;
//请求失败后，是否用IP重试
- (BOOL)shouldRetryWithIpForRequest:(YTKRequest *)request;
//记录一个被污染的HOST
- (void)insertBadHost:(NSString *)host;

- (NSString *)ipForHost:(NSString *)hostName;
- (NSString *)cacheIpForHost:(NSString *)hostName;

- (void)failIp:(id)ip forHost:(NSString *)host;

- (void)handleFailRequest:(YTKRequest *)request
              withSuccess:(void (^)(YTKBaseRequest *request))success
                  failure:(void (^)(YTKBaseRequest *request))failure;

- (void)dnsRetryWithRequest:(YTKRequest *)request
                    success:(void (^)(YTKBaseRequest *request))success
                    failure:(void (^)(YTKBaseRequest *request))failure;

- (NSString *)hostForRequest:(YTKRequest *)request;

- (void)queryIPForHost:(NSString *)host withCompletionBlock:(void(^)(BOOL succ))block;

+ (BOOL)isDNSError:(NSInteger)errorCode;

- (BOOL)isBadHostOutDate:(NSString *)badHost;
@end
